import datetime                                  # na=随机数1选商品，nb=随机数2选折扣
import random                                    # i=卡上的钱，o=花了多少钱，p=买了几件商品
na = random.randint(0,2)
list1 = ['烟20元','酒50元','糖100元',]
list2 = ['购物小票：']
list3 = ['0.8','没抽到折扣，不打','没抽到折扣，不打']
list4 = ['20','50','100']
print('欢迎光临超市，以下是在售物品：')
print(list1)
i = 500
o = 0
p = 0
print('你今天的幸运商品是：',end=' ')
print(list1[na])
print('你今天购买幸运商品会获得：',end=' ')
print(list3[na],end=' ')
print('折')
while True:
     buy = (input('请输入你想购买的物品，按x删除上一件购买的物品，按q结束购物:'))
     if buy == list1[na]:
         print('加入购物车成功')
         if i < 0.8 * int(list4[na]):
             print('钱不够啊，买不了了')
             break
         else :
          i = i - 0.8 * int(list4[na])
          o = o + 0.8 * int(list4[na])
          p = p + 1
          print('剩余钱:',i)
          list2.insert(2,'烟20元')
     elif buy == '烟20元':
        print('加入购物车成功')
        if i < 20:
           print('钱不够啊，买不了了')
           break
        else:
          i = i - 20
        o = o + 20
        p = p + 1
        print('剩余钱:',i)
        list2.insert(2,'烟20元')
     elif buy == '酒50元':
        print('加入购物车成功')
        if i < 50:
           print('钱不够啊，买不了了')
           break
        else:
         i = i - 50
        o = o + 50
        p = p + 1
        print('剩余钱:', i)
        list2.insert(2, '酒50元')
     elif buy == '糖100元':
        print('加入购物车成功')
        if i < 100:
           print('钱不够啊，买不了了')
           break
        else:
         i = i - 100
        o = o + 100
        p = p + 1
        print('剩余钱:', i)
        list2.insert(2, '糖100元')
     elif buy == 'q':
         break
     elif buy == 'x':
         print('上一件商品已从购物车删除')
         list2.pop()
         i = i + 50
         o = o - 50
         p = p - 1
     else:
         print('没有该商品，请重新输入')
print(list2)
print(datetime.datetime.now())
print('你卡上还有：',i,'元')
print('你一共购买了：',p,'件商品')
print('你一共花了：',o,'元')